package org.sdfc.model.attr

import com.documentum.fc.common.IDfId
import com.documentum.fc.common.IDfTime

import org.sdfc.model.attr.key._

/** Represents the type of an Attribute.
 */
abstract sealed class AttrType[+T] {
  
  /** Tests if the Attribute is repeating. */
  def isRepeating : Boolean
  
  /** Tests if the Attribute is single. */
  final def isSingle : Boolean = ! isRepeating
  
  /** Creates a KeyAttribute of given name based on this. */
  def createKeyAttribute(name : String) : KeyAttribute[T]
  
}


/** Refinement of AttrType for SingleAttribute.
 */
abstract class SingleAttrType[+T] extends AttrType[T] {
  
  /** False, by definition of this. */
  final def isRepeating = false
  
  /** Creates a KeyAttribute of given name based on this, refined to be a KSingleAttribute. */
  def createKeyAttribute(name : String) : KSingleAttribute[T]
  
}

/** Refinement of AttrType for RepeatingAttribute.
 */
abstract class RepeatingAttrType[+T] extends AttrType[T] {
  
  /** True, by definition of this. */
  final def isRepeating = true
  
  /** Creates a KeyAttribute of given name based on this, refined to be a KRepeatingAttribute. */
  def createKeyAttribute(name : String) : KRepeatingAttribute[T]
  
}


/** single/boolean AttrType
 */
case object SingleBooleanAttrType extends SingleAttrType[Boolean] {
  
  def createKeyAttribute(name : String) = new KSingleBooleanAttribute(name)

}

/** single/int AttrType
 */
case object SingleIntAttrType extends SingleAttrType[Int] {
  
  def createKeyAttribute(name : String) = new KSingleIntAttribute(name)

}

/** single/string AttrType
 */
case object SingleStringAttrType extends SingleAttrType[String] {
  
  def createKeyAttribute(name : String) = new KSingleStringAttribute(name)

}

/** single/id AttrType
 */
case object SingleIdAttrType extends SingleAttrType[IDfId] {
  
  def createKeyAttribute(name : String) = new KSingleIdAttribute(name)

}

/** single/time AttrType
 */
case object SingleTimeAttrType extends SingleAttrType[IDfTime] {
  
  def createKeyAttribute(name : String) = new KSingleTimeAttribute(name)

}

/** single/double AttrType
 */
case object SingleDoubleAttrType extends SingleAttrType[Double] {
  
  def createKeyAttribute(name : String) = new KSingleDoubleAttribute(name)

}


/** repeating/boolean AttrType
 */
case object RepeatingBooleanAttrType extends RepeatingAttrType[Boolean] {
  
  def createKeyAttribute(name : String) = new KRepeatingBooleanAttribute(name)

}

/** repeating/int AttrType
 */
case object RepeatingIntAttrType extends RepeatingAttrType[Int] {
  
  def createKeyAttribute(name : String) = new KRepeatingIntAttribute(name)

}

/** repeating/string AttrType
 */
case object RepeatingStringAttrType extends RepeatingAttrType[String] {
  
  def createKeyAttribute(name : String) = new KRepeatingStringAttribute(name)

}

/** repeating/id AttrType
 */
case object RepeatingIdAttrType extends RepeatingAttrType[IDfId] {
  
  def createKeyAttribute(name : String) = new KRepeatingIdAttribute(name)

}

/** repeating/time AttrType
 */
case object RepeatingTimeAttrType extends RepeatingAttrType[IDfTime] {
  
  def createKeyAttribute(name : String) = new KRepeatingTimeAttribute(name)

}

/** repeating/double AttrType
 */
case object RepeatingDoubleAttrType extends RepeatingAttrType[Double] {
  
  def createKeyAttribute(name : String)  = new KRepeatingDoubleAttribute(name)

}

